#include <fhe/math/Color.h>
#include <fhe/core/Registerers.h>

namespace fhe
{
  namespace core
  {
    Color::Color()
      : r( 1 )
      , g( 1 )
      , b( 1 )
      , a( 1 )
    {
    }
    
    Color::Color( double r_, double g_, double b_, double a_ )
      : r( r_ )
      , g( g_ )
      , b( b_ )
      , a( a_ )
    {
    }
    
    void Color::serialize( const Data::Ptr& data, Color color )
    {
      FileSystem::instance().serialize( data->addChild( "r" ), color.r );
      FileSystem::instance().serialize( data->addChild( "g" ), color.g );
      FileSystem::instance().serialize( data->addChild( "b" ), color.b );
      FileSystem::instance().serialize( data->addChild( "a" ), color.a );
    }
    
    Color Color::deserialize( const Data::Ptr& data )
    {
      return Color( data->hasChild( "r" ) ? 
                      FileSystem::instance().deserialize<double>( data->getChild( "r" ) ) :
                      1,
                    data->hasChild( "g" ) ? 
                      FileSystem::instance().deserialize<double>( data->getChild( "g" ) ) :
                      1,
                    data->hasChild( "b" ) ? 
                      FileSystem::instance().deserialize<double>( data->getChild( "b" ) ) :
                      1,
                    data->hasChild( "a" ) ? 
                      FileSystem::instance().deserialize<double>( data->getChild( "a" ) ) :
                      1 );
    }
    
    FHE_SERIALIZER_TYPE( Color );
  }
}
